package com.gupaoedu.baifc.singleton;

/**
 * projectName: baifc_singleton
 * packageName: com.gupaoedu.baifc.lazysingleton
 * Created: 2019/3/12.
 * Auther: baifc
 * Description: 懒汉式单例
 */
public class LazySingleton {

    private LazySingleton() {
//        if (lazySingleton != null) {
//            throw new RuntimeException("不允许创建多个实例！");
//        }
    }

    private static LazySingleton lazySingleton = null;

    public static LazySingleton getInstance() {
        // 线程安全
        if (lazySingleton == null) {
            synchronized (LazySingleton.class) {
                if (lazySingleton == null) {
                    lazySingleton = new LazySingleton();
                }
            }
        }

        return lazySingleton;
    }
}
